using System;
using System.Collections.Generic;
using System.Text;
using CodePlex.Resourceful.Amazon.S3;
using System.IO;
using System.Diagnostics;
using System.Reflection;
using CodePlex.Resourceful.Amazon.S3.Test;
using System.Text.RegularExpressions;
using CodePlex.Resourceful.Amazon.S3.Actions;
using System.Net;
using CodePlex.Resourceful.Sun.CloudStorage;
using CodePlex.Resourceful.Microsoft.Azure;
using System.Xml;
using CodePlex.Resourceful.Amazon.SQS;

namespace CodePlex.Resourceful.Examples
{
    public static class SQSExample
    {
        public static void Run()
        {

            string aws = Environment.GetEnvironmentVariable("AWS");

            string accessKeyID = aws.Split(':')[0];
            string secretAccessKey = aws.Split(':')[1];

          
            SQSClient client = new SQSClient(accessKeyID, secretAccessKey, false,HttpMethod.Get);
            client.Tracer.AddListener(Console.Out);


            

            string queueName = Guid.NewGuid().ToString();
           
            string url = Regex.Match(client.CreateQueue(queueName, null).AsString(), "<QueueUrl>(.*?)</QueueUrl>").Groups[1].Value;

            client.SendMessage(url, "helloworld");
            string receiptHandle = null;
            while (string.IsNullOrEmpty(receiptHandle))
                receiptHandle = Regex.Match(client.ReceiveMessage( url, null, null, null).AsString(), "<ReceiptHandle>(.*?)</ReceiptHandle>").Groups[1].Value;
            client.ChangeMessageVisibility(url, receiptHandle, TimeSpan.FromMinutes(30));
            client.DeleteMessage(url, receiptHandle);

            client.ListQueues(null);
            client.GetQueueAttributes(url,QueueAttributes.All);
            client.GetQueueAttributes( url, QueueAttributes.ApproximateNumberOfMessages | QueueAttributes.Policy);
            client.DeleteQueue( url);

       
            
        }




    }
}
